//
//  OrderDetailPhotoView.m
//  YunGou
//
//  Created by macbook on 16/5/24.
//  Copyright © 2016年 macbook. All rights reserved.
//

#import "OrderDetailPhotoView.h"
#import <UIImageView+WebCache.h>

@implementation OrderDetailPhotoView

+ (float)heightOfContent:(NSString *)imageList withInWidth:(float)width{
    NSArray *imageArray = [imageList componentsSeparatedByString:@","];
    NSArray *imageSplite = nil;
    if (imageArray.count == 0) {
        return 0;
    }else{
        if (imageArray.count > 3) {
            imageSplite = [imageArray subarrayWithRange:NSMakeRange(0, 3)];
        }else{
            imageSplite = imageArray;
        }
    }
    
    NSMutableArray *endArray = [NSMutableArray array];
    for (NSString *imagePath in imageSplite) {
        if (![imagePath isEqualToString:@""]) {
            [endArray addObject:imagePath];
        }
    }
    
    CGFloat imageX = 0;
    CGFloat imageY = 0;
    CGFloat imageW = width;
    CGFloat imageH = 0;
    for (NSInteger i = 0; i < endArray.count; i ++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [imageView sd_setImageWithURL:[NSURL URLWithString:[ImageUrl stringByAppendingString:endArray[i]]]];
        imageH = (imageView.image.size.height * width)/imageView.image.size.width;
        imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
        imageY += (8 + imageH);
    }
    return imageY;
}

- (void)setImageArray:(NSString *)imageList withInWidth:(float)width
{
    NSArray *imageArray = [imageList componentsSeparatedByString:@","];
    NSArray *imageSplite = nil;
    if (imageArray.count == 0) {
        return;
    }else{
        if (imageArray.count > 3) {
            imageSplite = [imageArray subarrayWithRange:NSMakeRange(0, 3)];
        }else{
            imageSplite = imageArray;
        }
    }
    NSMutableArray *endArray = [NSMutableArray array];
    for (NSString *imagePath in imageSplite) {
        if (![imagePath isEqualToString:@""]) {
            [endArray addObject:imagePath];
        }
    }
    CGFloat imageX = 0;
    CGFloat imageY = 0;
    CGFloat imageW = width;
    CGFloat imageH = 0;
    for (NSInteger i = 0; i < endArray.count; i ++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [imageView sd_setImageWithURL:[NSURL URLWithString:[ImageUrl stringByAppendingString:endArray[i]]]];
        imageH = (imageView.image.size.height * width)/imageView.image.size.width;
        imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
        imageY += (8 + imageH);
        [self addSubview:imageView];
    }
}


@end
